<?php

/*
 * Argument Assertion - check if certain keys of role and resource are the same
 * 
 * Possible use when you want to check if the resource object has a user_id attribute
 * with the same value of the role object (a user object).
 *
 * The assertion object requires an array of KEY => VALUE pairs, where the KEYs refer
 * to role attributes, and VALUEs to resource attributes.
 *
 * example : new Acl_Assert_Argument(array('primary_key_value'=>'user_id'));
 */
 
class Acl_Assert_Order implements Acl_Assert_Interface {
	
	public function __construct()
	{
		//
	}
	
	public function assert(Acl_Core $acl, $role = null, $resource = null, $privilege = null)
	{
		$role_uid      = $role->get_user_id   ();

		if ($privilege == 'modify')
		{
			if ($resource->merchant_uid() == $role_uid)
				return TRUE;
			else
				return FALSE;
		}

		if ($privilege == 'cancel')
		{
			if ($role_uid == $resource->merchant_uid() OR
				$role_uid == $resource->member_uid () )
				return TRUE;
			else
				return FALSE;
		}

		if ($privilege == 'read')
		{
			if ($role_uid == $resource->member_uid () )
				return TRUE;
			else
				return FALSE;
		}


		if ($privilege == 'comment')
		{
			if ($role_uid == $resource->merchant_uid() OR
				$role_uid == $resource->member_uid () )
				return TRUE;
			else
				return FALSE;
		}

		return FALSE;
	}
}
